package com.xintonghua.bussiness.ui.fragment.client.user;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.xintonghua.base.utils.MyTimeUtils;
import com.xintonghua.base.utils.MyUtils;
import com.xintonghua.base.utils.RefreshUtils;
import com.xintonghua.bussiness.EnumType;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.adapter.GoodAdapter;
import com.xintonghua.bussiness.adapter.MeiRongTestHistoryRecordAdapter;
import com.xintonghua.bussiness.adapter.OrderHomeAdapter;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.Contant;
import com.xintonghua.bussiness.bean.GoodsManageBean;
import com.xintonghua.bussiness.bean.GoodsManageResponse;
import com.xintonghua.bussiness.bean.HistoryRecordBean;
import com.xintonghua.bussiness.bean.ShopOrderListBean;
import com.xintonghua.bussiness.util.JsonUtil;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.addapp.pickers.picker.DatePicker;

/**
 * 客户信息里的美容测试====》美容测试====》美容测试历史记录
 */

public class MeiRongTestHistoryRecordActivity extends BaseActivity {
    @BindView(R.id.lv_search_product)
    XRecyclerView lvSearchProduct;
    String keyword = "";
    private int page = 1;
    private List<HistoryRecordBean> manageBeans = new ArrayList<>();
    //    GoodsManageResponse response;
    MeiRongTestHistoryRecordAdapter adapter;

    Contant contantbean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_list);
        ButterKnife.bind(this);
        contantbean = (Contant) JumpUtils.getSerializable(this, "data0");
        initUI();

    }

    @Override
    public void initUI() {
        super.initUI();
        onSimpleActionBar();
        setSimpleActionBar("美容测试历史");
        RefreshUtils.initList(this, lvSearchProduct, MyUtils.dip2px(this, 2), R.color.grey_bg);
        // keyword = getIntent().getStringExtra(BuildConfig.FLAVOR);
        adapter = new MeiRongTestHistoryRecordAdapter(this, manageBeans);
        adapter.setCheck(true);
        lvSearchProduct.setAdapter(adapter);
        lvSearchProduct.setLoadingListener(this);
        find();
    }

    private void find() {
//        httpCent.stockProducts(page, keyword, EnumType.ALL,
//                this, MyState.requestOne);
        httpCent.getBeautyTestList("" + contantbean.getId(), this, MyState.requestOne);
    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                try {
                    if (page == 1) {
                        manageBeans.clear();
                    }
                    List<HistoryRecordBean> response = JsonUtil.getListByJsonString((String) data, HistoryRecordBean.class);
                    manageBeans.addAll(response);
                    adapter.notifyDataSetChanged();
                    RefreshUtils.onRefresh(adapter, lvSearchProduct);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
        }

    }

    @Override
    public void onRefresh() {
        page = 1;
        find();
    }

    @Override
    public void onLoadMore() {
//        if (RefreshUtils.hasNext(response, adapter, lvSearchProduct)) {
        find();
        page++;
//        }
    }
}
